#include <header.h>

int workCmd(const char *realPath,const char *homePath){
    
//    //获取来自服务端的pwd
//    train_t train;
//    bzero(&train,sizeof(train));
//    char *realPath;
//    recv(netfd,&train.length,sizeof(train.length),MSG_WAITALL);
//    recv(netfd,train.data,train.length,MSG_WAITALL);
//    memcpy(&realPath,train.data,train.length);
//    printf("realPath=%s\n",realPath);
//    
//    //获得家目录
//    bzero(&train,sizeof(train));
//    char *homePath;
//    recv(netfd,&train.length,sizeof(train.length),MSG_WAITALL);
//    recv(netfd,train.data,train.length,MSG_WAITALL);
//    memcpy(&homePath,train.data,train.length);
//    printf("homePath=%s\n",homePath);
    
    //将绝对路径去掉家目录
    const char *relativePath;
    relativePath=realPath+strlen(homePath);
    printf("relativePath=%s\n",relativePath);

    //将相对路径分隔进入一个数组
    char *tokens[50];//最多路径个数为50
    int count=0;
    char *copyPath=strdup(relativePath);
    char *token=strtok(copyPath,"/");
    while(token!=NULL&&count<50){
        tokens[count++]=strdup(token);
        token=strtok(NULL,"/");
    }
    for(int i=0;i<count;i++){
        printf("tokens[%d]=%s\n",i,tokens[i]);
    }
    


    return 0;
}
//单元测试
int main(){
    const char *realPath="/home/user/documents/project/src";
    const char *homePath="/home/user";
    workCmd(realPath,homePath);
    return 0;
}
